package com.woniuxy.jwt.utils;

import cn.hutool.jwt.JWTUtil;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author yellow Docter
 * @date 2024-10-18
 * @desc 蜗牛创想：www.woniuxy.com
 */
@Component
public class TemplateJwt {

    public final byte [] key = "1234".getBytes();

    //创建token

    /**
     *  创建token
     * @param map   载荷
     * @return
     */
    public  String createToken(Map<String,Object> map){
        //载荷
        //创建token
        String token = JWTUtil.createToken(map, key);
        System.out.println("token = " + token);
        return token;
    }

    //校验
    /**
     *
     * @param token  传入token
     * @return
     */
    public boolean verify(String token){
        return JWTUtil.verify(token, key);
    }

    //解析
    public Object parse(String token,String key){

        Object payload = JWTUtil.parseToken(token).getPayload(key);
        return payload;
    }

}
